from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE, NUMBER

# 创建对象的基类
Base = declarative_base()

# 收付款流水中间表
class sfkTempList(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_SFKLIST_TEMP'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    FKZHMC = Column(VARCHAR2(200))  # 付款账号名称
    FKGS = Column(VARCHAR2(200))  # 付款归属
    SKZHMC = Column(VARCHAR2(200))  # 收款账号名称
    SKGS = Column(VARCHAR2(200))  # 收款归属
    FKJE = Column(NUMBER)  # 付款金额
    JS_YWFL = Column(VARCHAR2(200))  # 结算业务分类
    RQ = Column(VARCHAR2(40)) # 月份
    SCRQ = Column(DATE)  # 流水日期
    JYND = Column(NUMBER)  # 交易年度
    IS_SFK = Column(INTEGER) # 是否收付款

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=int(data.get('ID')) if data.get('ID') is not None else 0,
            FKZHMC=data.get('FKZHMC'),
            FKGS=data.get('FKGS'),
            SKZHMC=data.get('SKZHMC'),
            SKGS=data.get('SKGS'),
            FKJE=data.get('FKJE'),
            JS_YWFL=data.get('JS_YWFL'),
            RQ=data.get('RQ'),
            SCRQ=data.get('SCRQ'),
            JYND=data.get('JYND'),
            IS_SFK=data.get('IS_SFK')
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'FKZHMC': self.FKZHMC,
            'FKGS': self.FKGS,
            'SKZHMC': self.SKZHMC,
            'SKGS': self.SKGS,
            'FKJE': self.FKJE,
            'JS_YWFL': self.JS_YWFL,
            'RQ': self.RQ,
            'SCRQ': self.SCRQ,
            'JYND': self.JYND,
            'IS_SFK': self.IS_SFK
        }